package com.zzvcom.webapp.action.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.zzvcom.persist.model.admin.Config;
import com.zzvcom.service.admin.ConfigManager;
import com.zzvcom.utils.ExtMessage;

@Controller
@Scope("prototype")
public class MailAction
{

    private ConfigManager manager;

    private String mailaccount;

    private String mailpass;

    private String presubject;

    private String mailto;

    private ExtMessage msg = new ExtMessage();// 返回信息

    private Config config;

    public String execute()
    {
        config = manager.getConfig();
        return "config";
    }

    public String save()
    {
        config = manager.getConfig();
        manager
                .updateByHQL(
                        "update Config c set c.mailaccount=?,c.mailpass=?,c.presubject=?,c.mailto=?  where c.id=? ",
                        mailaccount, mailpass, presubject, mailto, config
                                .getId());
        manager.clearCache();
        msg.setInfo("邮件信息保存成功！");
        return "msg";
    }

    public ExtMessage getMsg()
    {
        return msg;
    }

    public void setMsg(ExtMessage msg)
    {
        this.msg = msg;
    }

    public ConfigManager getManager()
    {
        return manager;
    }

    @Autowired
    public void setManager(ConfigManager manager)
    {
        this.manager = manager;
    }

    public String getMailaccount()
    {
        return mailaccount;
    }

    public void setMailaccount(String mailaccount)
    {
        this.mailaccount = mailaccount;
    }

    public String getMailpass()
    {
        return mailpass;
    }

    public void setMailpass(String mailpass)
    {
        this.mailpass = mailpass;
    }

    public String getPresubject()
    {
        return presubject;
    }

    public void setPresubject(String presubject)
    {
        this.presubject = presubject;
    }

    public String getMailto()
    {
        return mailto;
    }

    public void setMailto(String mailto)
    {
        this.mailto = mailto;
    }

    public Config getConfig()
    {
        return config;
    }

    public void setConfig(Config config)
    {
        this.config = config;
    }

}
